**************************************************************
*HURRICANES AND GAS GOUGING - MAIN REPORTING AND OUTAGE REGRESSIONS
**************************************************************
frame copy default report_regs, replace
frame change report_regs
keep if sample_main==1
gsort station_id date

***
*CREATING VARIABLES

*Open
gen open = !missing(retail) | !missing(retail_midgrade) | !missing(retail_premium)

*Recode Outage Data 
gen outage_continuous = 0
replace outage_continuous = 0.05 if outage_level_daymax == 1
replace outage_continuous = 0.15 if outage_level_daymax == 2
replace outage_continuous = 0.25 if outage_level_daymax == 3
replace outage_continuous = 0.35 if outage_level_daymax == 4
replace outage_continuous = 0.50 if outage_level_daymax == 5
replace outage_continuous = 0.65 if outage_level_daymax == 6
replace outage_continuous = 0.80 if outage_level_daymax == 7
replace outage_continuous = 0.95 if outage_level_daymax == 8

*FEMA Disaster Declaration
egen fema = rowmax(fema_disaster fema_indiv_hh_disaster)	

*Creating day 0 event-study indicators
gsort station_id date
gen hur_landfall_d0=0 
	replace hur_landfall_d0=1 if BONCHAR_landfall==1 & date==`=td(12aug2004)'
	replace hur_landfall_d0=1 if FRANCES_landfall==1 & date==`=td(06sep2004)'
	replace hur_landfall_d0=1 if IVAN_landfall==1 & date==`=td(16sep2004)'
	replace hur_landfall_d0=1 if JEANNE_landfall==1 & date==`=td(26sep2004)'
	replace hur_landfall_d0=1 if ARLENE_landfall==1 & date==`=td(11jun2005)'
	replace hur_landfall_d0=1 if DENNIS_landfall==1 & date==`=td(10jul2005)'
	replace hur_landfall_d0=1 if KATRINA_FL_landfall==1 & date==`=td(25aug2005)'
	replace hur_landfall_d0=1 if KATRINA_LA_landfall==1 & date==`=td(29aug2005)'
	replace hur_landfall_d0=1 if RITA_landfall==1 & date==`=td(24sep2005)'
	replace hur_landfall_d0=1 if WILMA_landfall==1 & date==`=td(24oct2005)'
	replace hur_landfall_d0=1 if ALBERTO_landfall==1 & date==`=td(13jun2006)'
	replace hur_landfall_d0=1 if HUMBERTO_landfall==1 & date==`=td(13sep2007)'
	replace hur_landfall_d0=1 if GUSTAV_landfall==1 & date==`=td(01sep2008)'
	replace hur_landfall_d0=1 if IKE_landfall==1 & date==`=td(13sep2008)'
*
*Hurricane inland day 0
gen hur_inland_d0=0 
	replace hur_inland_d0=1 if BONCHAR_inland==1 & date==`=td(12aug2004)'
	replace hur_inland_d0=1 if FRANCES_inland==1 & date==`=td(06sep2004)'
	replace hur_inland_d0=1 if IVAN_inland==1 & date==`=td(16sep2004)'
	replace hur_inland_d0=1 if JEANNE_inland==1 & date==`=td(26sep2004)'
	replace hur_inland_d0=1 if ARLENE_inland==1 & date==`=td(11jun2005)'
	replace hur_inland_d0=1 if DENNIS_inland==1 & date==`=td(10jul2005)'
	replace hur_inland_d0=1 if KATRINA_FL_inland==1 & date==`=td(25aug2005)'
	replace hur_inland_d0=1 if KATRINA_LA_inland==1 & date==`=td(29aug2005)'
	replace hur_inland_d0=1 if RITA_inland==1 & date==`=td(24sep2005)'
	replace hur_inland_d0=1 if WILMA_inland==1 & date==`=td(24oct2005)'
	replace hur_inland_d0=1 if ALBERTO_inland==1 & date==`=td(13jun2006)'
	replace hur_inland_d0=1 if HUMBERTO_inland==1 & date==`=td(13sep2007)'
	replace hur_inland_d0=1 if GUSTAV_inland==1 & date==`=td(01sep2008)'
	replace hur_inland_d0=1 if IKE_inland==1 & date==`=td(13sep2008)'
*
*Creating 14-day event windows   
gen event_day=. //Event day variable
	replace event_day=0 if hur_landfall_d0==1|hur_inland_d0==1
	
*Indicators: 14 Days Prior to Hurricane for Different Samples
forvalues t = 1/14 {
	local n=-1*(`t')
	*Year check
	gen y=f`t'.year
	*Landfall indicator
	gen hur_landfall_dn`t' = 0
		replace hur_landfall_dn`t' = 1 if f`t'.hur_landfall_d0==1 & y==year
	*Inland
	gen hur_inland_dn`t'=0
		replace hur_inland_dn`t'= 1 if f`t'.hur_inland_d0==1  & y==year	
	*Event day  
	replace event_day=`n' if hur_landfall_dn`t'==1|hur_inland_dn`t'==1
	drop y
}
*
*Indicators: 14 Days After Hurricane
forvalues t = 1/14 {
	*Year check
	gen y=l`t'.year
	*Landfall indicator
	gen hur_landfall_d`t' = 0		
		replace hur_landfall_d`t' = 1 if l`t'.hur_landfall_d0==1 & y==year
	*Inland
	gen hur_inland_d`t'=0
		replace hur_inland_d`t' = 1 if l`t'.hur_inland_d0==1 & y==year
	*Event day  
	replace event_day=`t' if hur_landfall_d`t'==1|hur_inland_d`t'==1
	drop y		
}
*
order hur_landfall_dn14 hur_landfall_dn13 hur_landfall_dn12 hur_landfall_dn11 ///
      hur_landfall_dn10 hur_landfall_dn9 hur_landfall_dn8 hur_landfall_dn7 ///
	  hur_landfall_dn6 hur_landfall_dn5 hur_landfall_dn4 hur_landfall_dn3 ///
	  hur_landfall_dn2 hur_landfall_dn1 hur_landfall_d0 hur_landfall_d1 ///
	  hur_landfall_d2 hur_landfall_d3 hur_landfall_d4 hur_landfall_d5 ///
	  hur_landfall_d6 hur_landfall_d7 hur_landfall_d8 hur_landfall_d9 ///
	  hur_landfall_d10 hur_landfall_d11 hur_landfall_d12 hur_landfall_d13 ///
	  hur_landfall_d14 ///
	  hur_inland_dn14 hur_inland_dn13 hur_inland_dn12 hur_inland_dn11 hur_inland_dn10 ///
	  hur_inland_dn9 hur_inland_dn8 hur_inland_dn7 hur_inland_dn6 hur_inland_dn5 ///
	  hur_inland_dn4 hur_inland_dn3 hur_inland_dn2 hur_inland_dn1 hur_inland_d0 ///
	  hur_inland_d1 hur_inland_d2 hur_inland_d3 hur_inland_d4 hur_inland_d5 ///
	  hur_inland_d6 hur_inland_d7 hur_inland_d8 hur_inland_d9 hur_inland_d10 ///
	  hur_inland_d11 hur_inland_d12 hur_inland_d13 hur_inland_d14, last
	  
*Event window indicators 
egen window_landfall=rowtotal(hur_landfall_dn14-hur_landfall_d14)  //Event study - Landfall
egen window_inland=rowtotal(hur_inland_dn14-hur_inland_d14)  //Event study - Inland


********************************************************************************
*FIGURE 5 - CHANGES IN REPORTING BEHAVIOR
********************************************************************************
*			 
***********************************
*FIGURE 5(A) -  INLAND VS. LANDFALL AREAS
gen d=. in 1
gen xb_hur1 = . in 1
gen hi_hur1 = . in 1
gen lo_hur1 = . in 1	
gen xb_hur3 = . in 1
gen hi_hur3 = . in 1
gen lo_hur3 = . in 1

*****
*Hurricane Landfall - All Hurricanes, No Controls	
reghdfe open hur_landfall_dn14-hur_landfall_d14 ///
	if inrange(window_landfall, 1, 10), absorb(station_id year month) nocons cluster(county_FIPS)	

replace d=-14 in 1
replace xb_hur1=0 in 1
replace hi_hur1=0 in 1
replace lo_hur1=0 in 1	

forvalues i = 2/14 {
	local j=-1*(`i'-15)
	replace d=-1*`j' in `i'	
	lincom hur_landfall_dn`j'-hur_landfall_dn14
	replace xb_hur1    = r(estimate) in `i'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `i'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `i'

}

forvalues i = 0/14 {
	local j=`i'+15
	replace d=`i' in `j'
	lincom hur_landfall_d`i'-hur_landfall_dn14
	replace xb_hur1 = r(estimate) in `j'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `j'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `j'
}

*Hurricane Inland, Controls
reghdfe open hur_inland_dn14-hur_inland_d14 ///
	if inrange(window_inland, 1, 10), absorb(station_id year month dow) nocons cluster(county_FIPS)

replace xb_hur3=0 in 1
replace hi_hur3=0 in 1
replace lo_hur3=0 in 1	

forvalues i = 2/14 {
	local j=-1*(`i'-15)
	replace d=-1*`j' in `i'	
	lincom hur_inland_dn`j'-hur_inland_dn14
	replace xb_hur3 = r(estimate) in `i'
	replace hi_hur3 = r(estimate) + 1.96*r(se) in `i'
	replace lo_hur3 = r(estimate) - 1.96*r(se) in `i'
}

forvalues i = 0/14 {
	local j=`i'+15
	replace d=`i' in `j'
	lincom hur_inland_d`i'-hur_inland_dn14
	replace xb_hur3 = r(estimate) in `j'
	replace hi_hur3 = r(estimate) + 1.96*r(se) in `j'
	replace lo_hur3 = r(estimate) - 1.96*r(se) in `j'
}

tw(connected xb_hur1 d, m(O) mfcolor(white) mlcolor(black) msize(medium) lcolor(cranberry) lwidth(medthick) mlwidth(medium)) ///
    (connected xb_hur3 d, m(T) mfcolor(white) mlcolor(black) msize(medium) lcolor(yellow) lwidth(medthick) mlwidth(medium)) ///
    (line hi_hur1 d, lpattern(dash) lcolor(erose)) ///
    (line lo_hur1 d, lpattern(dash) lcolor(erose)), ///
    graphr(color(white)) ///
    yscale(noline) ///
    xtit("Days Before/After Hurricane Landfall") ///
    ytit("Change in Share Reporting") ///
    yline(0, lcolor(cranberry)) ///
    legend(order(1 "Landfall" 2 "Inland") size(vsmall) ///
    region(lcolor(white)) cols(1) ring(0) position(7)) ///
    xline(0,lcolor(black) lp(dash))
graph export $figs/closures_nocontrols_$outputdate.png, replace width(4000)
drop d-lo_hur3
*
***********************************
*FIGURE 5(B) -  LANDFALL AREAS WITH AN WITHOUT DEMAND/SUPPLY CONTROLS
gen d=. in 1
gen xb_hur1 = . in 1
gen hi_hur1 = . in 1
gen lo_hur1 = . in 1	
gen xb_hur2 = . in 1
gen hi_hur2 = . in 1
gen lo_hur2 = . in 1
*
*Hurricane Landfall - All Hurricanes, No Controls	
reghdfe open hur_landfall_dn14-hur_landfall_d14 ///
	if inrange(window_landfall, 1, 10), absorb(station_id year month) nocons cluster(county_FIPS)	
replace d=-14 in 1
replace xb_hur1=0 in 1
replace hi_hur1=0 in 1
replace lo_hur1=0 in 1	
*
forvalues i = 2/14 {
	local j=-1*(`i'-15)
	replace d=-1*`j' in `i'	
	lincom hur_landfall_dn`j'-hur_landfall_dn14
	replace xb_hur1    = r(estimate) in `i'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `i'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `i'

}
*
forvalues i = 0/14 {
	local j=`i'+15
	replace d=`i' in `j'
	lincom hur_landfall_d`i'-hur_landfall_dn14
	replace xb_hur1 = r(estimate) in `j'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `j'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `j'
}
*
*Controls
reghdfe open hur_landfall_dn14-hur_landfall_d14 ///
	tr_totvol outage_continuous fema prcp_near1 tmean_near1 CHRN CHRT CTSN CTST ///
	if inrange(window_landfall, 1, 10), absorb(station_id year month dow) nocons cluster(county_FIPS)
replace xb_hur2=0 in 1
replace hi_hur2=0 in 1
replace lo_hur2=0 in 1
*
forvalues i = 2/14 {
	local j=-1*(`i'-15)
	lincom hur_landfall_dn`j'-hur_landfall_dn14
	replace xb_hur2 = r(estimate) in `i'
	replace hi_hur2 = r(estimate) + 1.96*r(se)  in `i'
	replace lo_hur2 = r(estimate) - 1.96*r(se) in `i'

}
*
forvalues i = 0/14 {
	local j=`i'+15
	lincom hur_landfall_d`i'-hur_landfall_dn14
	replace xb_hur2 = r(estimate) in `j'
	replace hi_hur2 = r(estimate) + 1.96*r(se)  in `j'
	replace lo_hur2 = r(estimate) - 1.96*r(se) in `j'
}
*
*Graph
tw (connected xb_hur1 d, m(O) mfcolor(white) mlcolor(edkblue) msize(medium) lcolor(edkblue) lwidth(medthick) mlwidth(medium)) ///
    (connected xb_hur2 d, m(D) mfcolor(white) mlcolor(black) msize(medium) lcolor(dkorange) lwidth(medthick) mlwidth(medium)) ///
	(line hi_hur1 d, lpattern(dash) lcolor(erose)) ///
	(line lo_hur1 d, lpattern(dash) lcolor(erose)), ///
	graphr(color(white)) ///
	yscale(noline) ///
	xtit("Days Before/After Hurricane Landfall") ///
	ytit("Change in Share Reporting") ///
	ylabel( ,nogrid angle(0)) ///
	text(0.6 0 "Hurricane Landfall", place(e)) ///
	yline(0, lcolor(cranberry))  ///
	xline(0,lcolor(black) lp(dash)) ///
	legend(order(1 "Landfall - No Controls" 2 "Landfall - Controls ") size(vsmall) ///
	region(lcolor(white)) cols(1) ring(0) position(7)) 
graph export $figs/event_closing_$outputdate.png, replace width(4000)
drop d-lo_hur2


********************************************************************************
*FIGURE 6 - CHANGES IN REPORTING BY STATION TYPE
********************************************************************************
*			 
***********************************
*FIGURE 6(A) -  DIFFERENCE-IN-DIFFERENCES
reghdfe open pre_hur_brand hur_brand post_hur_brand ///
               pre_hur_ret hur_ret post_hur_ret ///
			   pre_hur_unbrand hur_unbrand post_hur_unbrand ///
			   CTST CHRT CTSN CHRN ///
			   tr_totvol outage_continuous fema prcp_near1 tmean_near1, ///
			   absorb(station_id year month dow) cluster(county_FIPS)	
estimates store brand
*
coefplot(brand), ///
	drop(_cons CTST CHRT CTSN CHRN tr_totvol outage_continuous fema prcp_near1 tmean_near1) ///
	xline(0, lc(cranberry)) graphregion(fcolor(white)) ///
	order(pre_hur_brand pre_hur_ret pre_hur_unbrand ///
	      hur_brand hur_ret hur_unbrand ///
	      post_hur_brand post_hur_ret post_hur_unbrand) ///
	m(D) mfcolor(white) mlcolor(edkblue) msize(medlarge) lcolor(edkblue)   ///
	headings(pre_hur_brand ="{bf:Pre-Hurricane}" ///
		   hur_brand="{bf: Hurricane}" ///
		   post_hur_brand="{bf: Post-Hurricane}", labcolor(edkblue) labsize(medlarge)) ///
	coeflabels(pre_hur_brand="Branded" hur_brand="Branded" post_hur_brand="Branded" ///
			   pre_hur_ret="Retailer" hur_ret="Retailer" post_hur_ret="Retailer" ///
			   pre_hur_unbrand="Unbranded" hur_unbrand="Unbranded" post_hur_unbrand="Unbranded", ///
				notick labsize(small))	
graph export $figs/report-branded-$outputdate.png, replace width(4000)

***********************************
*FIGURE 6(B) -  EVENT STUDY
gen d=. in 1
gen xb_hur1 = . in 1
gen hi_hur1 = . in 1
gen lo_hur1 = . in 1	
gen xb_hur2 = . in 1
gen hi_hur2 = . in 1
gen lo_hur2 = . in 1
gen xb_hur3 = . in 1
gen hi_hur3 = . in 1
gen lo_hur3 = . in 1
*
*BRANDED 
reghdfe open hur_landfall_dn14-hur_landfall_d14 ///
	tr_totvol outage_continuous fema prcp_near1 tmean_near1 CHRN CHRT CTSN CTST ///
	if inrange(window_landfall, 1, 10) & brand_maj == 1, absorb(station_id year month dow) nocons cluster(county_FIPS)
*
replace d=-14 in 1
replace xb_hur1=0 in 1
replace hi_hur1=0 in 1
replace lo_hur1=0 in 1	
*
forvalues i = 2/14 {
	local j=-1*(`i'-15)
	replace d=-1*`j' in `i'	
	lincom hur_landfall_dn`j'-hur_landfall_dn14
	replace xb_hur1 = r(estimate) in `i'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `i'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `i'

}
forvalues i = 0/14 {
	local j=`i'+15
	replace d=`i' in `j'
	lincom hur_landfall_d`i'-hur_landfall_dn14
	replace xb_hur1 = r(estimate) in `j'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `j'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `j'
}
*
*RETAIL
reghdfe open hur_landfall_dn14-hur_landfall_d14 ///
	tr_totvol outage_continuous fema prcp_near1 tmean_near1 CHRN CHRT CTSN CTST ///
	if inrange(window_landfall, 1, 10) & ret_maj == 1, absorb(station_id year month dow) nocons cluster(county_FIPS)
*
replace xb_hur2=0 in 1
replace hi_hur2=0 in 1
replace lo_hur2=0 in 1	
*
forvalues i = 2/14 {
	local j=-1*(`i'-15)
	lincom hur_landfall_dn`j'-hur_landfall_dn14
	replace xb_hur2 = r(estimate) in `i'
	replace hi_hur2 = r(estimate) + 1.96*r(se)  in `i'
	replace lo_hur2 = r(estimate) - 1.96*r(se) in `i'
}
*
forvalues i = 0/14 {
	local j=`i'+15
	lincom hur_landfall_d`i'-hur_landfall_dn14
	replace xb_hur2 = r(estimate) in `j'
	replace hi_hur2 = r(estimate) + 1.96*r(se)  in `j'
	replace lo_hur2 = r(estimate) - 1.96*r(se) in `j'
}
*
*UNBRANDED
reghdfe open hur_landfall_dn14-hur_landfall_d14 ///
	tr_totvol outage_continuous fema prcp_near1 tmean_near1 CHRN CHRT CTSN CTST ///
	if inrange(window_landfall, 1, 10) & unbranded == 1, absorb(station_id year month dow) nocons cluster(county_FIPS)
*
replace xb_hur3=0 in 1
replace hi_hur3=0 in 1
replace lo_hur3=0 in 1	
*
forvalues i = 2/14 {
	local j=-1*(`i'-15)
	lincom hur_landfall_dn`j'-hur_landfall_dn14
	replace xb_hur3 = r(estimate) in `i'
	replace hi_hur3 = r(estimate) + 1.96*r(se)  in `i'
	replace lo_hur3 = r(estimate) - 1.96*r(se) in `i'
}
*
forvalues i = 0/14 {
	local j=`i'+15
	lincom hur_landfall_d`i'-hur_landfall_dn14
	replace xb_hur3 = r(estimate) in `j'
	replace hi_hur3 = r(estimate) + 1.96*r(se)  in `j'
	replace lo_hur3 = r(estimate) - 1.96*r(se) in `j'
}
*
tw (connected xb_hur1 d, m(O) mfcolor(white) mlcolor(edkblue) msize(medium) lcolor(edkblue) lwidth(medthick) mlwidth(medium)) ///
    (connected xb_hur2 d, m(D) mfcolor(white) mlcolor(black) msize(medium) lcolor(dkorange) lwidth(medthick) mlwidth(medium)) ///
    (connected xb_hur3 d, m(T) mfcolor(white) mlcolor(black) msize(medium) lcolor(yellow) lwidth(medthick) mlwidth(medium)) ///
	(line hi_hur1 d, lpattern(dash) lcolor(erose)) ///
	(line lo_hur1 d, lpattern(dash) lcolor(erose)), ///
	graphr(color(white)) ///
	yscale(noline) ///
	xtit("Days Before/After Hurricane Landfall") ///
	ytit("Change in Share Reporting") ///
	ylabel( ,nogrid angle(0)) ///
	text(0.6 0 "Hurricane Landfall", place(e)) ///
	yline(0, lcolor(cranberry))   ///
	xline(0,lcolor(black) lp(dash)) ///
	legend(order(1 "Branded" 2 "Retail" 3 "Unbranded") size(vsmall) ///
	    region(lcolor(white)) cols(1) ring(0) position(7)) 
graph export $figs/event_branded_$outputdate.png, replace width(4000)
drop d-lo_hur3
frame change default